﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using eTMS.Controllers.LoaiDiemService;
using eTMS.Controllers;
using eTMS.Commons;
namespace eTMS.Controls{
   public class ComboBoxLoaiDiem : ComboBoxBindingBase<LoaiDiemEntity>
   {
		public ComboBoxLoaiDiem(){
            DropDownStyle = ComboBoxStyle.DropDownList;
	    }
		//Bind data to txtLoaiDiem
        public override void BindData(){
            this.DropDownStyle = ComboBoxStyle.DropDownList;
		    List<LoaiDiemEntity>lsLoaiDiem = new List<LoaiDiemEntity>(LoaiDiemController.ListLoaiDiemStatic.ToArray());
			lsLoaiDiem=FilterList(lsLoaiDiem);
		    if(IsAddChooseItem){
				LoaiDiemEntity eChooseItem = new LoaiDiemEntity();
				eChooseItem.TenLoaiDiem = Constants.CHOOSE_ITEM;
				lsLoaiDiem.Insert(0,eChooseItem);
			}		
		    if(IsAddAllItem){
				LoaiDiemEntity eChooseItem = new LoaiDiemEntity();
                eChooseItem.TenLoaiDiem = Constants.APP_ALL;
				lsLoaiDiem.Insert(0,eChooseItem);
			}			
		    this.DisplayMember = "TenLoaiDiem";
		    object currentSelected=this.SelectedValue;
		    this.ValueMember = "LoaiDiem_ID";
		    this.DataSource = lsLoaiDiem;
		    if(currentSelected==null){
				if(this.Items.Count>0){
					this.SelectedIndex=0;
				}
            }
            else{
					this.SelectedValue = currentSelected;
					if(this.SelectedValue==null){
						if(this.Items.Count>0){
						this.SelectedIndex=0;
					}
                }
            }
        }
	}
}
